﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Diagnostics;
using CSNN.GUI;

namespace CSNN
{
    /// <summary>
    /// Логика взаимодействия для Rocognition.xaml
    /// </summary>
    public partial class Rocognition : Window
    {
        private BindingList<NewImage> _NewImage;
        private int _inDemension;
        private Image imageToInput;
        private NeuralNetwork NNet;
        
        public Rocognition()
        {
            InitializeComponent();
        }

        public void SetImagesDemension(int InDemension, NeuralNetwork NeuralNet)
        {
            GridNewImage.Columns.Clear();

            this.NNet = NeuralNet;

            _inDemension = InDemension;
            
            _NewImage = new BindingList<NewImage>();

            for (int i = 0; i < InDemension; i++)
            {
                _NewImage.Add(new NewImage(1, "In " + i.ToString()));
            }

            GridNewImage.ItemsSource = _NewImage;
            GridNewImage.IsReadOnly = false;

        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void buttonRecognition_Click(object sender, RoutedEventArgs e)
        {
            imageToInput = new Image();
            imageToInput.SetImage(_NewImage.Count);

            Image outputImage = new Image();
            outputImage.SetImage(NNet.NeuralLayers[NNet.LayersCount - 1].NeuronsCount);

            for (int iInput = 0; iInput < _NewImage.Count; iInput++)
            {
                imageToInput.InputSignals[iInput] = _NewImage[iInput].Unit;
            }

            Stopwatch time = new Stopwatch();
            time.Start();

            outputImage = NNet.GetNeuralNetworkOut(imageToInput);

            time.Stop();

            textBlockRecognitionTime.Text = time.ElapsedMilliseconds.ToString() + " мс";
            textBlockRecognitionOut.Text = outputImage.ToString();
        }
    }
}
